<%--
  Created by IntelliJ IDEA.
  User: GuoLiang
  Date: 2025/2/7
  Time: 10:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="http://${pageContext.request.serverName }:${pageContext.request.serverPort }${pageContext.request.contextPath }/"/>
    <script type="text/javascript" src="static/jquery-2.1.1.min.js"></script>
</head>
<body>
<h1>测试Ajax</h1>
<script>
    /*方案一*/
    /* $.ajax({
         "url":"send/array/plan/one.html",
         "type":"post",
         "data":{
             "empIdArray":[5,8,12]
         }
     })*/
    /*方案二：不成立*/
    /*$.ajax({
        "url":"send/array/plan/one.html",
        "type":"post",
        "data":{
            "empId":5,
            "empId":8,
            "empId":12
        }
    })*/
    /*方案三*/
    /* var array = [5,8,12];
     var arrayStr = JSON.stringify(array);
     $.ajax({
         "url":"send/array/plan/three.html",
         "type":"post",
         "data":arrayStr,
         "contentType":"application/json;charset=UTF-8"
     })*/

    // 准备要发送的 JSON 数据
    var student = {
        "stuId": 999,
        "stuName": "tom",
        "stuAge": 23,
        "address": {
            "province": "shandong",
            "city": "heze",
            "street": "hello"
        },
        "schoolList": [
            {
                "schoolName": "schoolONe",
                "schoolSize": 500
            }, {
                "schoolName": "schoolTwo",
                "schoolSize": 1000
            }, {
                "schoolName": "schoolThree",
                "schoolSize": 2000
            }
        ],
        "scoreMap": {
            "yingyu": 100,
            "shuxue": 80,
            "wuli": 90
        }
    };
    var requestBody = JSON.stringify(student);
    $.ajax({
        "url": "save/student.html",
        "type": "post",
        "data": requestBody,
        "contentType": "application/json;charset=utf-8",
        "dataType": "text",
        "success": function (response) {
            console.log(response);
        },
        "error": function (response) {
            console.log(response);
        }
    })

</script>
</body>
</html>
